using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db.Hr.Attendance;


namespace HengTong.ViewModel.Hr.SysAttendanceShiftGroupVms
{
    public partial class SysAttendanceShiftGroupListVm : BaseListVm<SysAttendanceShiftGroupView, SysAttendanceShiftGroupSearcher>
    {

        protected override IEnumerable<IGridColumn<SysAttendanceShiftGroupView>> InitGridHeader()
        {
            return new List<GridColumn<SysAttendanceShiftGroupView>>{
                this.MakeGridHeader(x => x.Name),
                this.MakeGridHeader(x => x.Description),
                this.MakeGridHeader(x => x.Type),
                this.MakeGridHeader(x => x.SchedulePattern),
                this.MakeGridHeader(x => x.ShiftsName),
                this.MakeGridHeader(x => x.StandardWorkMinutes),
                this.MakeGridHeader(x => x.AttendanceDays),
                this.MakeGridHeader(x => x.Order),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysAttendanceShiftGroupView> GetSearchQuery()
        {
            var query = DC.Set<SysAttendanceShiftGroup>()
                .Select(x => new SysAttendanceShiftGroupView
                {
				    ID = x.ID,
                    Name = x.Name,
                    Description = x.Description,
                    Type = x.Type,
                    StandardWorkMinutes = x.StandardWorkMinutes,
                    AttendanceDays = x.AttendanceDays,
                    Order = x.Order,
                    SchedulePattern = x.SchedulePattern,
                    ShiftsName = x.Shifts.Select(y=>y.Shift.Name).ToSepratedString(null,","), 
                })
                .OrderBy(x => x.Order ?? 99.99m)
                .ThenBy(x => x.ID);
            return query;
        }
    }

    public class SysAttendanceShiftGroupView : SysAttendanceShiftGroup{
        [Display(Name = "班次名称")]
        public String ShiftsName { get; set; }

    }
}
